package com.letoken.platform.repo.admin.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.letoken.platform.repo.app.dao.BlockchainMapper;
import com.letoken.platform.repo.app.po.Blockchain;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * @author wyl
 * @date 2023/1/31 18:24
 * @Version 1.0
 */
@Log4j2
@Repository
public class AdminBlockchainManager {

    @Autowired
    private BlockchainMapper blockchainMapper;

    /**
     * 查询是否有重复的网络标识和网络名称
     *
     * @param netType
     * @param name
     * @return
     */
    public boolean queryByNetTypeOrName(String netType, String name, Integer id) {
        LambdaQueryWrapper<Blockchain> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.or(
                i -> i.eq(Blockchain::getNetType, netType)
                        .or()
                        .eq(Blockchain::getName, name)
        )
        .ne(id != null, Blockchain::getId, id);
        Integer count = blockchainMapper.selectCount(queryWrapper);
        return count > 0;
    }
}
